﻿@using System.Linq.Expressions;
@using BlazorComponent;
@using Masa.Blazor.Presets;
@using Microsoft.AspNetCore.Authorization;
@using Microsoft.Extensions.DependencyInjection
@using ThingsGateway.Admin.Application;
@using ThingsGateway.Core.Extension

@namespace ThingsGateway.Admin.Blazor
@inherits BasePopupComponentBase

<PModal Persistent Title=@AppService.I18n.T("授权角色") Value="Visible" Width=1600 ValueChanged=@((a=>{if(!a)
        ClosePopupAsync();}))
         OnSave="OnUsersSaveAsync">
     @if (Visible)
    {
        <MRow>
            <MCol Cols="6">
                <AppDataTable TItem="SysRole" SearchItem="RoleSelectorInput" AddItem="object" EditItem="object"
                              SearchModel="@_search"
                                IsShowSearchKey
                                Dense
                               QueryCallAsync="QueryCallAsync" IsMenuOperTemplate=false IsShowFilter=false
                                IsShowQueryButton>


                 <OtherToolbarTemplate>
                     <MButton OnClick="()=>{_choice.AddRange(context);_datatable.QueryClickAsync();}" Color="primary" Class="my-1 mx-2 ">
                         @AppService.I18n.T("添加")
                        </MButton>

                    </OtherToolbarTemplate>
                    <ItemColOperTemplate>

                        <MButton Text OnClick="()=>{_choice.Add(context.Item);_datatable.QueryClickAsync();}" Color="primary">
                             @AppService.I18n.T("添加")
                        </MButton>

                    </ItemColOperTemplate>

                </AppDataTable>
            </MCol>

            <MCol Cols="6">
                <AppDataTable @ref="_datatable" TItem="SysRole" SearchItem="RoleSelectorInput" AddItem="object" EditItem="object"
                              SearchModel="@_searchSelector"
                                Dense
                               QueryCallAsync="QueryCallSelectorAsync" IsMenuOperTemplate=false IsShowFilter=false>

                     <OtherToolbarTemplate>
                         <MButton OnClick="()=>{_choice.RemoveWhere(a=>context.Any(b=>b.Id==a.Id));_datatable.QueryClickAsync();}" Color="primary" Class="my-1 mx-2 ">
                             @AppService.I18n.T("移除")
                        </MButton>

                    </OtherToolbarTemplate>
                    <ItemColOperTemplate>

                        <MButton Text OnClick="()=>{_choice.Remove(context.Item);_datatable.QueryClickAsync();}" Color="primary">
                             @AppService.I18n.T("移除")
                        </MButton>

                    </ItemColOperTemplate>

                </AppDataTable>
            </MCol>
        </MRow>
    }
</PModal>



@code {
    private IAppDataTable _datatable;

}